Selectively blocking branch instruction prediction

ABSTRACT

Embodiments relate to selectively blocking branch instruction predictions. An aspect includes a computer system for performing selective branch prediction. The system includes memory and a processor, and the system is configured to perform a method. The method includes detecting a branch-prediction blocking instruction in a stream of instructions and blocking branch prediction of a predetermined number of branch instructions following the branch-prediction blocking instruction based on the detecting the branch-prediction blocking instruction.

BACKGROUND

The present embodiments relate to selectively blocking branchinstruction prediction, and more particularly to providing aninstruction within a stream of instructions to be executed to blockbranch prediction of a predetermined number of future branchinstructions.

Processors use pipelines to increase the speed with which an instructionstream may be processed. The pipeline may have a number of processingstages, and as one instruction is processed in one stage, a nextinstruction may be processed in an upstream stage. When the stream ofinstructions includes a branch instruction, the processor may need toexecute the branch instruction, or run the branch instruction throughthe whole pipeline, to determine a next instruction to execute. Toincrease efficiency, processors may determine when the instructionstream includes a branch instruction and may predict which instructionshould follow the branch instruction in the pipeline.

However, incorrect predictions by the processor may result in decreasedprocessing efficiency. For example, if the processor predicts a nextinstruction to follow a conditional branch instruction, but the branchis not taken, then the next instruction and any subsequent instructionsthat have been processed at various stages of the pipeline must becleared, and new instructions from the original stream including thebranch instruction must be provided at the start of the pipeline. As aresult, upstream stages of the pipeline may stand idle for multiplecycles following an incorrect branch prediction.

SUMMARY

Exemplary embodiments include a computer system for performing selectivebranch prediction. The system includes memory configured to storeinstructions and a processor configured to execute the instructions tocontrol the computer system to perform functions indicated by theinstructions. The system is configured to perform a method, whichincludes detecting, by the processor, a branch-prediction blockinginstruction in a stream of instructions and blocking, by the processor,branch prediction of a predetermined number of branch instructionsfollowing the branch-prediction blocking instruction based on thedetecting the branch-prediction blocking instruction.

Additional exemplary embodiments include a computer implemented methodfor performing selective branch prediction. The method includesdetecting, by the processor, a branch-prediction blocking instruction ina stream of instructions and blocking, by the processor, branchprediction of a predetermined number of branch instructions followingthe branch-prediction blocking instruction based on the detecting thebranch-prediction blocking instruction.

Further exemplary embodiments include a computer program product forperforming selective branch prediction. The computer program productincludes a tangible storage medium readable by a processing circuit andstoring instructions for execution by the processing circuit forperforming a method. The method includes detecting, by the processor, abranch-prediction blocking instruction in a stream of instructions andblocking, by the processor, branch prediction of a predetermined numberof branch instructions following the branch-prediction blockinginstruction based on the detecting the branch-prediction blockinginstruction.

Additional features and advantages are realized through the techniquesof the disclosed embodiments. Other embodiments and aspects of thedisclosure are described in detail herein. For a better understanding ofthe embodiments with the advantages and the features, refer to thedescription and to the drawings.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

The subject matter which is regarded as embodiments is particularlypointed out and distinctly claimed in the claims at the conclusion ofthe specification. The forgoing and other features, and advantages ofthe embodiments are apparent from the following detailed descriptiontaken in conjunction with the accompanying drawings in which:

FIG. 1 illustrates a block diagram of a selective branch predictionblocking system according to one embodiment of the present disclosure;

FIG. 2 illustrates an instruction execution assembly according to oneembodiment;

FIG. 3 illustrates an instruction compilation assembly according to oneembodiment;

FIG. 4 illustrates a flowchart of a method of selective branchprediction blocking according to one embodiment;

FIG. 5 illustrates a flowchart of a method of selective branchprediction blocking according to another embodiment;

FIG. 6 illustrates a computer system according to one embodiment; and

FIG. 7 illustrates a computer-readable medium according to oneembodiment of the present disclosure.

DETAILED DESCRIPTION

In exemplary embodiments, a branch prediction blocking instruction in astream of instructions prevents a branch prediction function from beingperformed on a predetermined number of branch instructions following theblocking instruction.

FIG. 1 illustrates a functional block diagram of a selective branchprediction blocking system 100 according to an embodiment of the presentdisclosure. The system 100 may include an instruction compilationassembly 110 and an instruction execution assembly 120. The instructioncompilation assembly 110 may receive as an input computer code in ahigh-level computer programming language and may convert the computercode to executable instructions. The instruction compilation assembly110 may include a blocking instruction insertion module 112 that insertsa branch prediction blocking instruction into a stream of instructionsin either the computer code or the executable instructions. The blockinginstruction insertion module 112 may be controlled by a user or by acomputer program. For example, the instruction compilation assembly 110may include a condition detection module 111 configured to recognize apredetermined condition within one or more of the high-level programmingcode, an intermediate programming code, or the executable instructions.If the condition is detected, the condition detection module 111 maytransmit a signal or instruction to the blocking instruction insertionmodule 112 to instruct the blocking instruction insertion module toinsert a branch prediction blocking instruction in a stream ofinstructions.

While FIG. 1 illustrates a condition detection module 111 and blockinginstruction insertion module 112, embodiments of the present disclosureencompass any means of providing a branch prediction blockinginstruction in a stream of instructions. For example, a user may inserta blocking instruction into programming code or executable instructions,and the instruction execution assembly 120 may execute the blockinginstruction in a stream of instructions. In other words, insertion ofthe blocking instruction may be based on analysis by an instructioncompilation assembly, or by analysis by a user who may use theinstruction compilation assembly 110 to insert the blocking instructioninto a stream of instructions at a stage of writing programming code,writing intermediate code, or writing processor-executable instructions.

A condition that may be detected by the condition detection module 111may include detecting a certain type of branch instruction, detecting acertain type of code in which the branch instruction resides, detectingparticular addresses, operands, or registers accessed by the branchinstruction, detecting that the branch instruction is a specificpre-designated branch instruction, or any other condition. For example,a particular branch instruction may resolve in the branch not beingtaken 60% of the time, while performing branch prediction may result ina correct prediction rate of 10%. The particular branch instruction maybe identified as being difficult to predict or unpredictable, and a useror condition detection module 111 may insert a blocking instruction intoa stream of instructions upstream of the unpredictable instruction. As aresult, when the stream of instructions is executed, the unpredictableinstruction may not have branch prediction performed.

The instruction execution assembly 120 executes a stream of instructionsby fetching, decoding, issuing, and executing the instructions. Theinstruction execution assembly 120 may further include a conditiondetection module 121 to detect a condition in the stream ofinstructions, and a blocking instruction insertion module 122 to inserta blocking instruction into the stream of instructions based ondetecting the condition by the condition detection module 121. Thecondition detection modules 111 and 121 and the blocking instructioninsertion modules 112 and 122 are represented with dashed lines toindicate that embodiments of the present disclosure encompass aselective branch prediction blocking system 100 including all of thecondition detection modules 111 and 121 and the blocking instructioninsertion modules 112 and 122, including only the condition detectionmodule 111 and the blocking instruction insertion module 112, includingonly the condition detection module 121 and the blocking instructioninsertion module 122, including only one or both of the blockinginstruction insertion modules 112 or 122, or including none of thecondition detection modules 111 and 121 and the blocking instructioninsertion modules 112 and 122. In such an example, a user may draft codein a programming language that is executed normally by the instructioncompilation assembly 110 and provided to the instruction executionassembly 120 for execution without conditions being detected by theinstruction compilation assembly 110 or the instruction executionassembly 120.

A condition that may be detected by the condition detection module 121may include detecting a certain type of branch instruction, detecting acertain type of code in which the branch instruction resides, detectingparticular addresses, operands, or registers accessed by the branchinstruction, detecting that the branch instruction is a specificpre-designated branch instruction, or any other condition.

The instruction execution assembly includes a blocking instructiondetection module 123 for detecting the blocking instruction in thestream of instructions. When the blocking instruction is detected, theblocking instruction detection module 123 controls the branch predictionblocking module 124 to skip or block branch prediction of apredetermined number of branch instructions following the blockinginstruction. The blocking instruction detection module 123 may controlthe branch prediction blocking module 124 to block every branchinstruction, every conditional branch instruction, particular classes ortypes of branch instructions, or specific branch instructions havingparticular target addresses.

Once the predetermined number of branch instructions has been skipped orblocked, the branch prediction blocking module 124 may automaticallyresume performing branch prediction operations on the branchinstructions specified by the blocking instruction. In one embodiment,the predetermined number of branch instructions is programmable andchangeable. For example, the blocking instruction may include an integerrepresenting the number of branch instructions for which branchprediction operations will be skipped or blocked. In another embodiment,the blocking instruction may contain no explicit information regarding anumber of branch instructions to be skipped or blocked, and the blockinginstruction detection module 123 may supply a default number of branchinstructions to be skipped, where the default number is a finite number.

For example, the condition detection module 111 may detect a particularbranch instruction during compiling, where the particular branchinstruction is defined as a branch instruction for which branchprediction should not be performed. The condition detection module 111may indicate to the blocking instruction insertion module 112 that theparticular branch instruction has been detected, and the blockinginstruction insertion module 112 may insert a branch prediction blockinginstruction in the executable instructions upstream from the particularbranch instruction. The branch prediction blocking instruction mayinclude an integer of “1” to indicate to the instruction executionassembly that only one following branch instruction should have branchprediction operations skipped.

In another example, the condition detection module 111 may detect aparticular type of code being compiled, such as code designated as being“sensitive” for which branch predictions should not be performed. Thecondition detection module 111 may indicate to the blocking instructioninsertion module 112 that the particular type of code has been detected,and the blocking instruction insertion module 112 may insert a branchprediction blocking instruction in the executable instructions upstreamfrom the particular type of code. The blocking instruction insertionmodule 112 may determine a number of branch instructions located in thesensitive code, and may generate a branch prediction blockinginstruction to indicate to the instruction execution assembly that onlythe number of branch instructions corresponding to the number of branchinstructions in the sensitive code should have branch predictionoperations skipped. The blocking instruction insertion module 112 mayinsert the blocking instruction a predetermined number of instructionsupstream from the sensitive code, such that when the blockinginstruction is executed by the instruction execution assembly 120, thesensitive code may not yet be in an instruction execution pipeline,thereby preventing lost processing time by preventing branch predictionwhen a branch of the sensitive code is fetched.

Although an example of “sensitive” code is described above for purposesof illustration, it is understood that embodiments of the presentdisclosure encompass inserting instructions to block branch predictionsbased on detecting any predetermined or pre-designated type ofinstructions or block of instructions.

In another example, the instruction execution assembly 120 maydetermine, based on a history of executed branch operations, that aparticular type of branch instruction is unpredictable, or has asuccessful branch prediction less than a predetermined threshold. Theinstruction execution assembly 120 may instruct the condition detectionmodule 121 to detect the particular type of branch instruction. Theparticular branch instruction may be identified, for example, byidentifying an address of the branch instruction and an address of anext instruction targeted by the branch instruction. When the conditiondetection module 121 detects the particular type of branch instruction,the condition detection module 121 controls the blocking instructioninsertion module 122 to insert an instruction into a stream ofinstructions being executed to skip or block branch prediction of theparticular instruction. The blocking instruction insertion module 122may provide an integer, such as “1”, within the instruction to indicateto the branch prediction blocking module 124 that only one followingbranch instruction should have a branch prediction function skipped orblocked.

In one embodiment, the particular branch instruction is located in astream of code, and the blocking instruction insertion module 122inserts the blocking instruction into the stream of code upstream fromthe particular branch instruction. The blocking instruction may beinserted far enough upstream from the particular branch instruction thatwhen the stream of instructions is provided to an instruction executionpipeline, the particular branch instruction may not be decoded yet whenthe blocking instruction executes.

The blocking instruction detection module 123 detects the blockinginstruction including the integer indicating a number of branchinstructions for which the branch prediction should be skipped orblocked. The branch prediction blocking module 124 blocks thepredetermined number of branch instructions from having branchprediction performed, and clears the blocking instruction to performbranch prediction on the particular type of branch instruction in thestream of instructions after the predetermined number of branchinstructions indicated by the blocking instruction has been skipped orblocked from having branch prediction performed.

FIG. 2 illustrates a block diagram of an instruction execution assembly200 according to an embodiment of the present disclosure. Theinstruction execution assembly 200 may correspond to the instructionexecution assembly 120 of FIG. 1. For example, in some embodiments oneor more of the instruction fetch unit 202, the branch prediction unit206, and the execution units 205 may correspond to the blockinginstruction detection module 123 and the branch prediction blockingmodule 124. In addition, the fetch unit 202 and the branch predictionunit 206 may correspond to the condition detection module 121 and theblocking instruction insertion module 122 of FIG. 1. Although FIG. 2illustrates one embodiment of an instruction execution assembly 200, itis understood that embodiments of the present disclosure encompass anyinstruction execution assembly that detects a blocking instruction andblocks or skips a predetermined number of branch prediction operationsbased on the detected blocking instruction.

The instruction execution assembly 200 may comprise one processing coreof a plurality of processing cores in a multi-threading processor. Theinstruction execution assembly 200 includes level-1 instruction cache(L1 Icache) 201, which stores program instructions and an instructionfetch unit 202 which fetches the instructions from the L1 Icache 201. Inparticular, the L1 Icache 201 provides loading of instruction streams inconjunction with the instruction fetch unit 202.

The fetched instructions are decoded by an instruction decode unit (IDU)203 into instruction processing data. The IDU 203 provides theinstructions to an issue unit 204 which controls the issuing of theinstructions various execution units 205, such as one or more fixedpoint units for executing general operations and one or more floatingpoint units for executing floating point operations.

The instruction execution assembly 200 includes a branch prediction unit206 in communication with the instruction fetch unit 202 for predictingtarget addresses of branch instructions. For example, the branchprediction unit 206 may include a branch target buffer (BTB) 207 forstoring branch target addresses associated with predicted branches. Thebranch prediction unit 206 may further include a branch history unit 208for storing patterns of taken and not-taken branch results forpreviously-resolved branch instructions. The branch history unit 208 maybe implemented as part of the BTB 207. In one embodiment, the branchprediction unit 206 includes a branch prediction control unit 209, whichmay turn on and off the branch prediction function using a predictionblocking unit 210, may analyze the branch history to determinedunpredictable branches, and may perform any additional control oranalysis functions related to branch prediction functions.

While the branch prediction unit 206 is illustrated as a separatefunctional block from the instruction fetch unit 202, embodiments of thepresent disclosure encompass an instruction fetch unit 202 that includesa branch prediction unit 206 within the instruction fetch unit 202. Forexample, one or more processors, memory, logic, and program code may beshared among the instruction fetch unit 202 and the branch predictionunit 206. In addition, while the branch prediction control unit 209 isillustrated as being separate from the execution units 205, embodimentsof the present disclosure encompass execution units 205 that executeblocking instructions to block the instruction fetch unit 202 and branchprediction unit 206 from performing branch prediction operations.

In operation, a stream of instructions flows through the instructionexecution assembly 200. The instruction fetch unit 202 may fetch theinstructions from the L1 Icache 201 in a predetermined order based onprevious instructions. The instruction fetch unit 202 may fetch a blockof instructions at once from the L1 Icache 201 and may store the blockof instructions, along with any non-decoded instructions from previousfetch operations, in the instruction storage 210.

In one embodiment, the stream of instructions includes a branchprediction blocking instruction having been provided by a user or acompiler. The branch prediction blocking instruction may flow throughthe pipeline and may be executed by the execution units 205. Based onthe execution of the blocking instruction, the execution units 205 mayprovide control signals to the prediction blocking unit 210 to blockbranch prediction operations of a predetermined number of followingbranch instructions. The prediction operations may be blocked, forexample, by preventing the instruction fetch unit 202 from accessing thebranch target buffer 207. In addition, the execution units 205 may beprevented by the blocking instruction from providing branch informationof the predetermined number of branch instructions to the branch historyunit 208 when the predetermined number of branch instructions areexecuted by the execution units 205.

In another embodiment, the instruction fetch unit 202 may identify aparticular branch instruction, type of branch instruction, or type ofinstruction surrounding the branch instructions. The identifiedparticular branch instruction may correspond to a type of branchinstruction identified as not having a branch prediction operationperformed. A string of instructions may include, for example, thefollowing:

Load, add, store, store, multiply, branch, load, load, add, store

The particular branch instruction or type of branch instruction may beidentified, for example, by determining an address of the branchinstruction and addresses targeted by the branch instruction. When theparticular branch instruction, type of branch instruction, or type ofinstruction surrounding the branch instructions is identified by theinstruction fetch unit 202 or the branch prediction unit 206 the branchprediction control unit 209 may generate an instruction to be insertedinto the stream of instructions upstream from the identified branchinstruction. Upon execution of the blocking instruction, the executionunits 205 may provide control signals to the prediction blocking unit210 to block branch prediction operations of a predetermined number offollowing branch instructions. The prediction operations may be blocked,for example, by preventing the instruction fetch unit 202 from accessingthe branch target buffer 207. In addition, the execution units 205 maybe prevented by the blocking instruction from providing branchinformation of the predetermined number of branch instructions to thebranch history unit 208 when the predetermined number of branchinstructions are executed by the execution units 205.

In one embodiment, the branch prediction control unit 209 may analyzethe branch prediction history to determine a particular branchinstruction that is unpredictable, or that has a level of successfulprediction below a predetermined threshold. The branch predictioncontrol unit 209 may store the identified branch instructioninformation, and may compare the identified branch instructioninformation to fetched branch instructions to determine whether togenerate the blocking instruction.

An example of the insertion of the branch prediction-blockinginstruction follows:

Load, add, store, blk_bpl_branch_(—)1, store, multiply, branch, load,load, add, store

In the example string of instructions above, the instructionblk_bpl_branch_(—)1 instructs the branch prediction unit 206 and/or theinstruction fetch unit 202 to skip one branch prediction operation. Inother words, when the next branch is detected in the string ofinstructions, the instruction fetch unit 202 does not obtain branchprediction information from the BTB 207 of the branch prediction unit206.

When a branch instruction in the string of instructions is identified,the branch prediction control unit 209 may determine whether a branchprediction operation should be performed, and the instruction fetch unit202 may consult the branch target buffer 207 to predict whichinstruction should be fetched to be decoded after the branchinstruction. In particular, the branch target buffer 207 may provide theinstruction fetch unit 202 with a predicted target address of apredicted branch instruction corresponding to the branch instructionidentified by the instruction fetch unit 202, allowing the instructionfetch unit 202 to fetch instructions at the predicted target address.

The fetched instructions are decoded by the instruction decode unit 203and issued to the appropriate execution units 205 by the issue unit 204based on a type of operation being carried out by the instruction. Theexecution units 205 determine whether branch conditions of conditionalbranch instructions are met, and whether a branch of a conditionalbranch instruction or an unconditional branch is taken. The executionunits 205 may provide the information regarding whether branches havebeen taken to the branch history unit 208, which may be used to predictfuture branches.

In embodiments of the present disclosure, the branch-prediction blockinginstruction, which may be provided by the branch prediction control unit209, may include an integer value representing a number of branchinstructions for which the branch prediction function should be skippedor blocked. The integer may be any whole number including 1 and up toany desired whole number. Upon blocking branch prediction for a numberof branch instructions equal to the integer value, the branch predictionunit 206 and the instruction fetch unit 202 may resume branch predictionoperations for branch instructions in the stream of instructions. Theinstruction provided by the branch prediction control unit 209 mayfurther include information such as a type of branch for which thebranch prediction function should be skipped or blocked. In other words,the instruction may prevent branch prediction for a predetermined numberof one type of branch instruction while permitting branch predictionoperations for all other types of branch instructions.

FIG. 3 illustrates a block diagram of an instruction compilationassembly 300 according to an embodiment of the present disclosure. Theinstruction compilation assembly 300 may correspond to the instructioncompilation assembly 110 of FIG. 1, for example.

The instruction compilation assembly 300 includes memory 310 and acompiler 320. The memory 311 may store programming code 311, such ashigh-level programming code generated by a user or by a computerprogram. The programming code 311 is provided to a code analyzer 321 ofthe compiler 323, which may analyze the programming code and based onthe analysis, the executable instruction generator 322 may convert theprogramming code to executable instructions 312 which may be stored inthe memory 310. The executable instructions may be read by a processor,such as by the instruction execution assembly 200 of FIG. 2, to executethe instructions to control a computer to perform the functionsindicated by the executable instructions 312.

In one embodiment, the programming code includes instructions forblocking branch prediction. A blocking instruction may include apredetermined number of branch instructions that should have branchprediction skipped or blocked following the blocking instruction. Theblocking instruction may also include information about a branchinginstruction, such as a type of branch instruction or a specific branchinstruction, that should have the branch prediction function blocked orskipped. The code analyzer 321 may analyze the programming code 311 andmay indicate to the executable instruction generator 322 that theblocking instruction of the programming code corresponds to a blockinginstruction to be generated by the executable instruction generator 322.The executable instruction generator 322 generates the executableinstructions 312 including the blocking instruction. The executableinstructions 312 may be generated and stored as a stream of instructionsexecutable in sequence.

In another embodiment, the code analyzer 321 is configured or programmedto analyze the programming code 311 and provide an analysis of theprogramming code to the executable instruction generator 322 and ablocking instruction insertion unit 323. When the code analyzer 321analyzes code corresponding to one or more predefined or predeterminedconditions, the blocking instruction insertion unit 323 may controleither the code analyzer 321 to insert into the programming code 311 aninstruction corresponding to a branch prediction blocking instruction.Alternatively, the blocking instruction insertion unit 323 may controlthe executable instruction generator 322 to insert an executable branchprediction blocking instruction into the string of executableinstructions 312. For example, the code analyzer 321 may analyze theprogramming code 321 and identify a particular branch instruction withinthe programming code. The blocking instruction insertion unit 323 mayrecognize the particular branch instruction as being a type of branchinstruction for which branch prediction should be skipped or blocked,and may instruct the code analyzer 321 or the executable instructiongenerator 322 to provide a branch prediction blocking instructionupstream from the particular branch instruction to prevent branchprediction of the particular branch instruction during processing of theexecutable instructions 312. The blocking instruction may be inserted apredetermined number of instructions upstream such that duringprocessing, interruption of an instruction execution pipeline may beminimized. For example, the blocking instruction may be insertedsufficiently upstream such that when the blocking instruction isexecuted, the particular branch instruction may not yet have beendecoded.

Although FIGS. 1-3 illustrate detecting conditions based on aninstruction stream by an instruction execution assembly 200 and aninstruction compilation assembly 300, embodiments of the presentdisclosure encompass any means of detecting conditions based on theinstruction stream. For example, in one embodiment a computer programexternal to the instruction execution assembly 200 may monitor executionof branch instructions and may identify branch instructions for whichbranch prediction should be blocked. The computer program may provide tothe instruction execution assembly 200 or memory the branch-predictionblocking instruction prior to processing a particular branchinstruction.

FIG. 4 illustrates a flow diagram of a method according to oneembodiment of the present disclosure. In block 401, it is determinedwhether a branch prediction blocking instruction is encountered duringexecution of a stream of instructions. For example, an execution unit ofan instruction execution pipeline may execute a branch predictionblocking instruction. In block 402, the blocking instruction causes abranch prediction block to be set. For example, an execution unit mayprovide instructions to an instruction fetch unit to control theinstruction fetch unit to not perform a branch prediction operation fora number of branch instructions following the blocking instruction. Thenumber of blocked branch prediction operations is a finite number of 1or more. In one embodiment, the number is defined in the blockinginstruction. In one embodiment, the blocking instruction furtherspecifies a type of branch instruction for which branch predictionshould be skipped.

In block 403, it is determined whether a branch instruction isencountered that corresponds to the type of branch instruction for whicha branch prediction is not to be performed. If the proscribed branchinstruction is detected in block 403, then a branch prediction functionis blocked for that instruction in block 404. Blocking the branchprediction may include preventing a fetch unit from accessing a branchtarget buffer and preventing information from the branch instructionfrom being entered into the branch target buffer and a branch historyunit, for example.

In block 405, it is determined whether a number, N, of branchinstructions specified by the branch prediction blocking instruction hasbeen encountered. For example, the branch prediction blockinginstruction may include an integer value from 1 to any number greaterthan 1 to indicate a number of branch instructions for which a branchprediction operation is to be skipped or blocked.

If it is determined in block 405 that the designated number, N, ofbranch instructions has been encountered, the branch prediction blockinginstruction is cleared in block 406, and subsequent branch instructionsmay be subject to normal branch prediction operations.

FIG. 5 illustrates a flow diagram of a method according to anotherembodiment of the present disclosure. In block 501, it is determinedwhether a branch prediction blocking condition is met. The blockingcondition may be based on an identified branch instruction in a streamof fetched instructions, on characteristics of other instructions in thestream of instructions, on pre-programmed instructions regarding when toperform branch prediction or on which types of branch instructionsbranch prediction should be performed, on an analysis of previous branchinstructions, such as a determination that certain branch instructionsare unpredictable, or based on any other desired condition.

If the condition is detected in block 501, then a branch predictionblocking instruction is inserted into the stream of instructions inblock 502. For example, if the condition relates to an identified branchinstruction in a stream of instructions, then the blocking instructionmay be inserted upstream of the identified branch instruction to preventbranch prediction of the identified branch instruction. The branchprediction blocking instruction may specify a very narrow range ofbranch instructions for which branch prediction is skipped, or thebranch prediction instruction may prevent branch prediction of any typeof conditional branch instruction.

In block 503, it is determined whether a branch instruction isencountered that corresponds to the type of branch instruction for whicha branch prediction is not to be performed. If the proscribed branchinstruction is detected in block 503, then a branch prediction functionis blocked for that instruction in block 504. Blocking the branchprediction may include preventing a fetch unit from accessing a branchtarget buffer or preventing information from the branch instruction frombeing entered into the branch target buffer and a branch history unit,for example.

In block 505, it is determined whether a number, N, of branchinstructions specified by the branch prediction blocking instruction hasbeen encountered. For example, the branch prediction blockinginstruction may include an integer value from 1 to any number greaterthan 1 to indicate a number of branch instructions for which a branchprediction operation is to be skipped or blocked.

If it is determined in block 505 that the designated number, N, ofbranch instructions has been encountered, the branch prediction blockinginstruction is cleared in block 506, and subsequent branch instructionsmay be subject to normal branch prediction operations.

FIG. 6 illustrates a block diagram of a system 600 for selectivelyblocking branch prediction operations according to one embodiment. Themethods described herein can be implemented in hardware, software (e.g.,firmware), or a combination thereof. In an exemplary embodiment, themethods described herein are implemented in hardware as part of themicroprocessor of a special or general-purpose digital computer, such asa personal computer, workstation, minicomputer, or mainframe computer.The system 600 therefore includes a general-purpose computer 601.

In an exemplary embodiment, in terms of hardware architecture, as shownin FIG. 6, the computer 601 includes a processor 605, which may be amulti-threading processor 605 configured to execute instructionssimultaneously or out-of-order, memory 610 coupled to a memorycontroller 615, and one or more input and/or output (I/O) devices 640,645 (or peripherals) that are communicatively coupled via a localinput/output controller 635. The input/output controller 635 can be, forexample but not limited to, one or more buses or other wired or wirelessconnections, as is known in the art. The input/output controller 635 mayhave additional elements, which are omitted for simplicity, such ascontrollers, buffers (caches), drivers, repeaters, and receivers, toenable communications. Further, the local interface may include address,control, and/or data connections to enable appropriate communicationsamong the aforementioned components.

The processor 605 is a hardware device for executing software,particularly that stored in storage 620, such as cache storage, ormemory 610. The processor 605 can be any custom made or commerciallyavailable processor, a central processing unit (CPU), an auxiliaryprocessor among several processors associated with the computer 601, asemiconductor based microprocessor (in the form of a microchip or chipset), a macroprocessor, or generally any device for executinginstructions. The processor 605 may include portions of the instructionexecution assembly 200 of FIG. 2, such as the branch prediction unit206, the instruction fetch unit 202, and the branch prediction blockingunit 210.

The memory 610 can include any one or combination of volatile memoryelements (e.g., random access memory (RAM, such as DRAM, SRAM, SDRAM,etc.)) and nonvolatile memory elements (e.g., ROM, erasable programmableread only memory (EPROM), electronically erasable programmable read onlymemory (EEPROM), programmable read only memory (PROM), tape, compactdisc read only memory (CD-ROM), disk, diskette, cartridge, cassette orthe like, etc.). Moreover, the memory 610 may incorporate electronic,magnetic, optical, and/or other types of storage media. Note that thememory 610 can have a distributed architecture, where various componentsare situated remote from one another, but can be accessed by theprocessor 605.

The instructions in memory 610 may include one or more separateprograms, each of which comprises an ordered listing of executableinstructions for implementing logical functions. In the example of FIG.6, the instructions in the memory 610 a suitable operating system (OS)611. The operating system 611 essentially controls the execution ofother computer programs and provides scheduling, input-output control,file and data management, memory management, and communication controland related services.

In an exemplary embodiment, a conventional keyboard 650 and mouse 655can be coupled to the input/output controller 635. Other output devicessuch as the I/O devices 640, 645 may include input devices, for examplebut not limited to a printer, a scanner, microphone, and the like.Finally, the I/O devices 640, 645 may further include devices thatcommunicate both inputs and outputs, for instance but not limited to, anetwork interface card (NIC) or modulator/demodulator (for accessingother files, devices, systems, or a network), a radio frequency (RF) orother transceiver, a telephonic interface, a bridge, a router, and thelike. The system 600 can further include a display controller 625coupled to a display 630. In an exemplary embodiment, the system 600 canfurther include a network interface 660 for coupling to a network 665.The network 665 can be an IP-based network for communication between thecomputer 601 and any external server, client and the like via abroadband connection. The network 665 transmits and receives databetween the computer 601 and external systems. In an exemplaryembodiment, network 665 can be a managed IP network administered by aservice provider. The network 665 may be implemented in a wirelessfashion, e.g., using wireless protocols and technologies, such as WiFi,WiMax, etc. The network 665 can also be a packet-switched network suchas a local area network, wide area network, metropolitan area network,Internet network, or other similar type of network environment. Thenetwork 665 may be a fixed wireless network, a wireless local areanetwork (LAN), a wireless wide area network (WAN) a personal areanetwork (PAN), a virtual private network (VPN), intranet or othersuitable network system and includes equipment for receiving andtransmitting signals.

If the computer 601 is a PC, workstation, intelligent device or thelike, the instructions in the memory 610 may further include a basicinput output system (BIOS) (omitted for simplicity). The BIOS is a setof essential software routines that initialize and test hardware atstartup, start the OS 611, and support the transfer of data among thehardware devices. The BIOS is stored in ROM so that the BIOS can beexecuted when the computer 601 is activated.

When the computer 601 is in operation, the processor 605 is configuredto execute instructions stored within the memory 610, to communicatedata to and from the memory 610, and to generally control operations ofthe computer 601 pursuant to the instructions.

In an exemplary embodiment, selective branch prediction methodsdescribed herein can be implemented with any or a combination of thefollowing technologies, which are each well known in the art: a discretelogic circuit(s) having logic gates for implementing logic functionsupon data signals, an application specific integrated circuit (ASIC)having appropriate combinational logic gates, a programmable gatearray(s) (PGA), a field programmable gate array (FPGA), etc.

As will be appreciated by one skilled in the art, one or more aspects ofthe present embodiments may be embodied as a system, method or computerprogram product. Accordingly, one or more aspects of the presentembodiments may take the form of an entirely hardware embodiment, anentirely software embodiment (including firmware, resident software,micro-code, etc.) or an embodiment combining software and hardwareaspects that may all generally be referred to herein as a “circuit,”“module” or “system”. Furthermore, one or more aspects of the presentembodiments may take the form of a computer program product embodied inone or more computer readable medium(s) having computer readable programcode embodied thereon.

Any combination of one or more computer readable medium(s) may beutilized. The computer readable medium may be a computer readablestorage medium. A computer readable storage medium may be, for example,but not limited to, an electronic, magnetic, optical, electromagnetic,infrared or semiconductor system, apparatus, or device, or any suitablecombination of the foregoing. More specific examples (a non-exhaustivelist) of the computer readable storage medium include the following: anelectrical connection having one or more wires, a portable computerdiskette, a hard disk, a random access memory (RAM), a read-only memory(ROM), an erasable programmable read-only memory (EPROM or Flashmemory), an optical fiber, a portable compact disc read-only memory(CD-ROM), an optical storage device, a magnetic storage device, or anysuitable combination of the foregoing. In the context of this document,a computer readable storage medium may be any tangible medium that cancontain or store a program for use by or in connection with aninstruction execution system, apparatus, or device.

Referring now to FIG. 7, in one example a computer program product 710includes, for instance, one or more storage media 712, wherein the mediamay be tangible and/or non-transitory, to store computer readableprogram code means or logic 714 thereon to provide and facilitate one ormore aspects of embodiments described herein.

Program code, when created and stored on a tangible medium (includingbut not limited to electronic memory modules (RAM), flash memory,Compact Discs (CDs), DVDs, Magnetic Tape and the like is often referredto as a “computer program product”. The computer program product mediumis typically readable by a processing circuit preferably in a computersystem for execution by the processing circuit. Such program code may becreated using a compiler or assembler for example, to assembleinstructions, that, when executed perform aspects of the embodiments.

Embodiments include a computer system, method, computer program product,and any other device or apparatus for performing selective branchprediction. Embodiments include detecting a branch prediction-blockinginstruction in a stream of instructions and blocking branch predictionof a predetermined number of branch instructions based on the detectingthe branch prediction-blocking instruction. The detecting and blockingmay be performed by a processor.

In one embodiment, the predetermined number is specified in thebranch-prediction blocking instruction. Another embodiment includespreventing information regarding the predetermined number of branchoperations from being stored for later branch prediction operations. Thepreventing may be performed by a processor.

Another embodiment includes detecting a predetermined condition based onthe stream of instructions and inserting the branch-prediction blockinginstruction into the stream of instructions based on the detecting thepredetermined condition. In one embodiment, the stream of instructionsis a stream of instructions in a processing pipeline of a processor, thepredetermined condition comprises determining that a fetched branchinstruction corresponds to a predetermined type of branch instruction,and inserting the branch-prediction blocking instruction into the streamof instructions includes inserting the branch-prediction blockinginstruction upstream from the fetched branch instruction

In one embodiment, the predetermined condition is a determination that abranch instruction within the stream of instructions is difficult topredict based on past branch predictions. In one embodiment, thepredetermined condition is a characteristic of non-branch instructionsin the stream of instructions. Another embodiment includes permittingthe branch-prediction operation of branch instructions based on adetermination that the predetermined number of branch-predictionoperations has been blocked.

Technical effects and benefits include improving processing performanceby preventing branch predictions of branch instructions that may resultin lower processing efficiency, such as branch instructions that have ahistory of unpredictability. In addition, the branch predictions may beselectively blocked by providing an instruction for blocking only apredetermined number of branch predictions, including blocking only anext branch prediction operation. Accordingly, in an instruction streamhaving a large number of branch operations, or in which only a smallnumber of known branch instructions is unpredictable, the number ofbranch predictions performed may be maximized while targeting only thedesired branch instructions as being blocked from having branchpredictions performed.

While embodiments of the present disclosure have been described abovewith respect to prediction and blocking of branch instructions by way ofexample, it is understood that embodiments of the present disclosureencompass detecting any predetermined type of instruction and insertinga blocking instruction in a stream of instructions to block any type ofprediction scheme from being performed.

The terminology used herein is for the purpose of describing particularembodiments only and is not intended to be limiting of embodiments. Asused herein, the singular forms “a”, “an” and “the” are intended toinclude the plural forms as well, unless the context clearly indicatesotherwise. It will be further understood that the terms “comprises”and/or “comprising,” when used in this specification, specify thepresence of stated features, integers, steps, operations, elements,and/or components, but do not preclude the presence or addition of oneor more other features, integers, steps, operations, elements,components, and/or groups thereof.

The corresponding structures, materials, acts, and equivalents of allmeans or step plus function elements in the claims below are intended toinclude any structure, material, or act for performing the function incombination with other claimed elements as specifically claimed. Thedescription of embodiments have been presented for purposes ofillustration and description, but is not intended to be exhaustive orlimited to the embodiments in the form disclosed. Many modifications andvariations will be apparent to those of ordinary skill in the artwithout departing from the scope and spirit of the embodiments. Theembodiments were chosen and described in order to best explain theprinciples and the practical application, and to enable others ofordinary skill in the art to understand the embodiments with variousmodifications as are suited to the particular use contemplated.

Computer program code for carrying out operations for aspects of theembodiments may be written in any combination of one or more programminglanguages, including an object oriented programming language such asJava, Smalltalk, C++ or the like and conventional procedural programminglanguages, such as the “C” programming language or similar programminglanguages. The program code may execute entirely on the user's computer,partly on the user's computer, as a stand-alone software package, partlyon the user's computer and partly on a remote computer or entirely onthe remote computer or server. In the latter scenario, the remotecomputer may be connected to the user's computer through any type ofnetwork, including a local area network (LAN) or a wide area network(WAN), or the connection may be made to an external computer (forexample, through the Internet using an Internet Service Provider).

Aspects of embodiments are described above with reference to flowchartillustrations and/or schematic diagrams of methods, apparatus (systems)and computer program products according to embodiments. It will beunderstood that each block of the flowchart illustrations and/or blockdiagrams, and combinations of blocks in the flowchart illustrationsand/or block diagrams, can be implemented by computer programinstructions. These computer program instructions may be provided to aprocessor of a general purpose computer, special purpose computer, orother programmable data processing apparatus to produce a machine, suchthat the instructions, which execute via the processor of the computeror other programmable data processing apparatus, create means forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks.

These computer program instructions may also be stored in a computerreadable medium that can direct a computer, other programmable dataprocessing apparatus, or other devices to function in a particularmanner, such that the instructions stored in the computer readablemedium produce an article of manufacture including instructions whichimplement the function/act specified in the flowchart and/or blockdiagram block or blocks.

The computer program instructions may also be loaded onto a computer,other programmable data processing apparatus, or other devices to causea series of operational steps to be performed on the computer, otherprogrammable apparatus or other devices to produce a computerimplemented process such that the instructions which execute on thecomputer or other programmable apparatus provide processes forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks.

The flowchart and block diagrams in the Figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods, and computer program products according to variousembodiments. In this regard, each block in the flowchart or blockdiagrams may represent a module, segment, or portion of code, whichcomprises one or more executable instructions for implementing thespecified logical function(s). It should also be noted that, in somealternative implementations, the functions noted in the block may occurout of the order noted in the figures. For example, two blocks shown insuccession may, in fact, be executed substantially concurrently, or theblocks may sometimes be executed in the reverse order, depending uponthe functionality involved. It will also be noted that each block of theblock diagrams and/or flowchart illustration, and combinations of blocksin the block diagrams and/or flowchart illustration, can be implementedby special purpose hardware-based systems that perform the specifiedfunctions or acts, or combinations of special purpose hardware andcomputer instructions.

1. A computer system for performing selective branch prediction, thesystem comprising: memory configured to store instructions; and aprocessor configured to execute the instructions to control the computersystem to perform functions indicated by the instructions, the systemconfigured to perform a method comprising: detecting, by the processor,a branch-prediction blocking instruction in a stream of instructions;and blocking, by the processor, branch prediction of a predeterminednumber of branch instructions following the branch-prediction blockinginstruction based on the detecting the branch-prediction blockinginstruction.
 2. The computer system according to claim 1, wherein thepredetermined number is specified in the branch-prediction blockinginstruction.
 3. The computer system according to claim 1, the methodfurther comprising: preventing, by the processor, information regardingthe predetermined number of branch operations from being stored forlater branch prediction operations.
 4. The computer system according toclaim 1, the method further comprising: detecting, by the processor, apredetermined condition based on the stream of instructions; andinserting, by the processor, the branch-prediction blocking instructioninto the stream of instructions based on the detecting the predeterminedcondition.
 5. The computer system according to claim 4, wherein thestream of instructions is a stream of instructions in a processingpipeline of the processor, the predetermined condition comprisesdetermining that a fetched branch instruction corresponds to apredetermined type of branch instruction, and inserting thebranch-prediction blocking instruction into the stream of instructionsincludes inserting the branch-prediction blocking instruction upstreamfrom the fetched branch instruction.
 6. The computer system according toclaim 4, wherein the predetermined condition is a determination that abranch instruction within the stream of instructions is difficult topredict based on past branch predictions.
 7. The computer systemaccording to claim 4, wherein the predetermined condition is acharacteristic of non-branch instructions in the stream of instructions.8. The computer system according to claim 1, the method furthercomprising: permitting the branch-prediction operation of branchinstructions based on a determination that the predetermined number ofbranch-prediction operations has been blocked.
 9. (canceled) 10.(canceled)
 11. (canceled)
 12. (canceled)
 13. (canceled)
 14. (canceled)15. (canceled)
 16. A computer program product for performing selectivebranch prediction, the computer program product comprising: a tangiblestorage medium readable by a processing circuit and storing instructionsfor execution by the processing circuit for performing a methodcomprising: detecting, by a processor, a branch-prediction blockinginstruction in a stream of instructions; and blocking, by the processor,branch prediction of a predetermined number of branch instructionsfollowing the branch-prediction blocking instruction based on thedetecting the branch-prediction blocking instruction.
 17. The computerprogram product according to claim 16, the method further comprising:preventing information regarding the predetermined number ofbranch-prediction operations from being stored for later branchprediction operations.
 18. The computer program product according toclaim 16, the method further comprising: detecting, by the processor, apredetermined condition based on the stream of instructions; andinserting, by the processor, the branch-prediction blocking instructioninto the stream of instructions based on the detecting the predeterminedcondition.
 19. The computer program product according to claim 18,wherein the predetermined condition comprises determining that a fetchedbranch instruction corresponds to a predetermined type of branchinstruction.
 20. The computer program product according to claim 16, themethod further comprising: permitting the branch prediction operation ofbranch instructions based on a determination that the predeterminednumber of branch-prediction operations has been blocked.